package com.party.core.service.commune.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.commune.CMemberIntegralCountReadDao;
import com.party.core.dao.write.commune.CMemberIntegralCountWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.commune.CMemberIntegralCount;
import com.party.core.service.commune.ICMemberIntegralCountService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @ClassName TjMemberIntegralService
 * @Description
 * @Author shenliuhai
 * @Date 2020/4/15 17:19
 **/
@Service
public class CMemberIntegralCountService implements ICMemberIntegralCountService {


    @Autowired
    private CMemberIntegralCountReadDao integralReadDao;

    @Autowired
    private CMemberIntegralCountWriteDao integralWriteDao;


    @Override
    public String insert(CMemberIntegralCount t) {
        BaseModel.preInsert(t);
        boolean result = integralWriteDao.insert(t);
        if (result) {
            return t.getId();
        }
        return null;
    }

    @Override
    public boolean update(CMemberIntegralCount t) {
        t.setUpdateDate(new Date());
        return integralWriteDao.update(t);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return integralWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return integralWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return integralWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return integralWriteDao.batchDelete(ids);
    }

    @Override
    public CMemberIntegralCount get(String id) {
        return integralReadDao.get(id);
    }

    @Override
    public List<CMemberIntegralCount> listPage(CMemberIntegralCount cMemberIntegralCount, Page page) {
        return integralReadDao.listPage(cMemberIntegralCount,page);
    }

    @Override
    public List<CMemberIntegralCount> list(CMemberIntegralCount cMemberIntegralCount) {
        return integralReadDao.listPage(cMemberIntegralCount,null);
    }

    @Override
    public List<CMemberIntegralCount> batchList(Set<String> ids, CMemberIntegralCount cMemberIntegralCount, Page page) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        return integralReadDao.batchList(ids,new HashedMap(),page);
    }

    @Override
    public CMemberIntegralCount getByMemberId(String memberId) {

        return integralReadDao.getByMemberId(memberId);
    }
}
